package castorss.src;

import java.util.ArrayList;
import java.util.List;

import com.google.code.rome.android.repackaged.com.sun.syndication.feed.synd.SyndEntry;

import castorss.src.rss.RSSUrl;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class EntryAdapter extends BaseAdapter 
{

	ArrayList<Entry> list;
	LayoutInflater inflater;
	
	public EntryAdapter(Context context, ArrayList<Entry> list_) 
	{
		super();
		inflater = LayoutInflater.from(context);
		this.list = list_;
	}
	
	@Override
	public int getCount() 
	{
		return list.size();
	}

	@Override
	public Object getItem(int position) 
	{
		return list.get(position);
	}

	@Override
	public long getItemId(int position) 
	{
		return position;
	}
	
	private class ViewHolder {
		TextView read;
		TextView title;
		TextView date;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		ViewHolder holder;
		
		if(convertView == null) 
		{
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.entry, null);
			holder.title = (TextView)convertView.findViewById(R.id.entry_title);
			holder.date = (TextView)convertView.findViewById(R.id.entry_date);
			convertView.setTag(holder);
		}
		else 
		{
			holder = (ViewHolder) convertView.getTag();
		}
		
		if(((Entry)list.get(position)).getRead() == 0)
		{
			holder.title.setTextColor(0xFFFFD700);
		}
		else
		{
			holder.title.setTextColor(0xFFFFFFFF);
		}
		holder.title.setText(((Entry)list.get(position)).getTitle());
		holder.date.setText(((Entry)list.get(position)).getDate());
		
		return convertView;
	}
}
